from commentGet import commentSort
import csv
from crawlStep1 import crawlStep1

def crawlStep2(urlsLists):
    file = open("comment.csv", "a", encoding="UTF8")
    csv_write=csv.writer(file)
    file2 = open("openedCount.txt", "r")
    itemCount = int(file2.read())
    for i in range(itemCount, itemCount + 5):
        if i < len(urlsLists):
            commentLists = commentSort(urlsLists[i][0])
            for j in range(len(commentLists)):
                    csv_write.writerow([str(i + 1), urlsLists[i][0], urlsLists[i][1], commentLists[j][0], commentLists[j][1]])
        else:
            print("已读完所有数据") #弹窗
            break
    file3 = open("openedCount.txt", "w")
    itemCount = i
    file3.write(str(itemCount))
    file.close()
    file2.close()
    file3.close()

if __name__=='__main__':

    crawlStep2(crawlStep1())